<?php
	defined('RUN') or die('No access');

	class RssController
	{
		public function index()
		{
			header("Content-Type: application/xhtml+xml; charset=UTF-8");
			
			$rssfeed = '<?xml version="1.0" encoding="UTF-8"?>';
			$rssfeed .= '<rss version="2.0">';
			$rssfeed .= '<channel>';
			$rssfeed .= '<title><![CDATA[ ' . Config::get('page_name') . ' ]]></title>';
			$rssfeed .= '<link><![CDATA[ http://www.terntrip.com.vn ]]></link>';
			$rssfeed .= '<description><![CDATA[ ' . Config::get('page_description') . ' ]]></description>';
			
			$entries = Model::get('post')->getLastest(20);
			
			foreach ($entries as $entry)
			{
				$rssfeed .= '<item>';
				$rssfeed .= '<title><![CDATA[ ' . $entry['title'] . ' ]]></title>';
				$rssfeed .= '<description><![CDATA[ ' . $entry['description'] . ' ]]></description>';
				$rssfeed .= '<link><![CDATA[ ' . Url::anchor(String::toUrl($entry['title']) . "-p" . $entry['id']) . ' ]]></link>';
				$rssfeed .= '<pubDate><![CDATA[ ' . $entry['timepost'] . ' ]]></pubDate>';
				$rssfeed .= '</item>';
			}
			
			$rssfeed .= '</channel>';
			$rssfeed .= '</rss>';
		 
			echo $rssfeed;
		}
	}
